#include <iostream>
#include <queue>
#include <string>
#include <list>

using namespace std;

class TwoQueueStack{
public:
  TwoQueueStack(){
  }
  void push(int pushInt){
    data.push(pushInt);
  }
  int peek(){
    if(data.empty()) {
      throw std::runtime_error("stack is empty");
    }
    while(data.size()!=1){
      help.push(data.front());
      data.pop();
    }
    int res=data.front();
    help.push(res);
    data.pop();
    std::swap(data,help);
    return res;
  }
  int pop(){
     if(data.empty()) {
      throw std::runtime_error("stack is empty");
    }
    while(data.size()!=1){
      help.push(data.front());
      data.pop();
    }
    int res=data.front();
    data.pop();
    std::swap(data,help);
    return res;
  }
  
private:
std::queue<int> data;
std::queue<int> help;

};